// 获取屏幕宽高
const width = document.body.clientWidth,
      height = document.body.clientHeight;
//Create a Pixi Application
let app = new PIXI.Application({
  width: width,
  height: height*4
});
// 创建资源加载器，进行资源预加载
const loader = new PIXI.loaders.Loader();
loader.add('bg', './imgs/bg.jpg')
      .add('dot', './imgs/dot.png')
      .add('line', './imgs/line.png')
      .add('eye_open', './imgs/eye_open.png')
      .add('eye_close', './imgs/eye_close.png')
      .add('hand', './imgs/hand.png')
      .add('text', './imgs/text.png')
      .add('boy', './imgs/boy.png')
      .add('bed_boy', './imgs/bed_boy.png')
      .add('bg_2', './imgs/bg_2.jpg');
loader.on("progress", function(target, resource) {  //加载进度
  document.getElementById('percent').innerText = target.progress+"%";
});
loader.once('complete', function(target, resource) {  //加载完成
  document.getElementById('loading').style.display = 'none';
  //Add the canvas that Pixi automatically created for you to the HTML document
  document.body.appendChild(app.view);
});
loader.load(setup);
function setup() {
  const resources = PIXI.loader.resources;
  const Sprite = PIXI.Sprite;
  const Texture = PIXI.Texture;

  let container_1 = new PIXI.Container();
  // let bgSprite = PIXI.Sprite.fromImage('bg');
  // let sprite = new PIXI.Sprite(
  //   PIXI.loader.resources["bg"].texture
  // );
  // bgSprite.width = 400;
  // bgSprite.height = 2400;
  // container_1.addChild(bgSprite);
  // 创建背景...
  let background = PIXI.Sprite.fromImage('bg');
  background.width = width;
  background.height = height;
  //将背景添加到舞台
  container_1.addChild(background);
  app.stage.addChild(container_1);
}
